﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using LibKetoan;

namespace Ketoan
{
	/// <summary>
	/// Summary description for frmDm.
	/// </summary>
	public class frmBcnghang : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button butKetthuc;
		private AccessData a;
		private DataTable dt=new DataTable();
		private DataTable dtnh=new DataTable();
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button butMoi;
		private System.Windows.Forms.Button butSua;
		private System.Windows.Forms.Button butLuu;
		private System.Windows.Forms.Button butBoqua;
		private System.Windows.Forms.Button butHuy;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.NumericUpDown stt;
		private long l_id;
		private int i_userid;
		private string user,s_mmyy;
		private System.Windows.Forms.TextBox ten;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox ma;
		private System.Windows.Forms.CheckBox chkHide;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox chucnang;
		private System.Windows.Forms.ComboBox loai;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.ComboBox idnh;
		private System.Windows.Forms.TextBox account;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.TextBox report;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.TextBox tkno;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.CheckBox baocao;
		private System.Windows.Forms.TextBox tkco;
		private System.Windows.Forms.CheckBox sophieu;
		private System.Windows.Forms.CheckBox dutoanns;
		private System.Windows.Forms.Button btn_in;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmBcnghang(AccessData acc,int userid,string mmyy)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			a=acc;i_userid=userid;s_mmyy=mmyy;
			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmBcnghang));
            this.dataGrid1 = new System.Windows.Forms.DataGrid();
            this.butKetthuc = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.ten = new System.Windows.Forms.TextBox();
            this.butMoi = new System.Windows.Forms.Button();
            this.butSua = new System.Windows.Forms.Button();
            this.butLuu = new System.Windows.Forms.Button();
            this.butBoqua = new System.Windows.Forms.Button();
            this.butHuy = new System.Windows.Forms.Button();
            this.label3 = new System.Windows.Forms.Label();
            this.stt = new System.Windows.Forms.NumericUpDown();
            this.label1 = new System.Windows.Forms.Label();
            this.ma = new System.Windows.Forms.TextBox();
            this.chkHide = new System.Windows.Forms.CheckBox();
            this.loai = new System.Windows.Forms.ComboBox();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.chucnang = new System.Windows.Forms.ComboBox();
            this.label7 = new System.Windows.Forms.Label();
            this.idnh = new System.Windows.Forms.ComboBox();
            this.account = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.report = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.tkno = new System.Windows.Forms.TextBox();
            this.tkco = new System.Windows.Forms.TextBox();
            this.label10 = new System.Windows.Forms.Label();
            this.baocao = new System.Windows.Forms.CheckBox();
            this.sophieu = new System.Windows.Forms.CheckBox();
            this.dutoanns = new System.Windows.Forms.CheckBox();
            this.btn_in = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.stt)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGrid1
            // 
            this.dataGrid1.AlternatingBackColor = System.Drawing.Color.Lavender;
            this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                        | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.dataGrid1.BackColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.BackgroundColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.dataGrid1.CaptionBackColor = System.Drawing.SystemColors.Control;
            this.dataGrid1.CaptionFont = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.CaptionForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.DataMember = "";
            this.dataGrid1.FlatMode = true;
            this.dataGrid1.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.dataGrid1.ForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.GridLineColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.GridLineStyle = System.Windows.Forms.DataGridLineStyle.None;
            this.dataGrid1.HeaderFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
            this.dataGrid1.HeaderForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.LinkColor = System.Drawing.Color.Teal;
            this.dataGrid1.Location = new System.Drawing.Point(8, 12);
            this.dataGrid1.Name = "dataGrid1";
            this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.Gainsboro;
            this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.MidnightBlue;
            this.dataGrid1.ReadOnly = true;
            this.dataGrid1.RowHeaderWidth = 10;
            this.dataGrid1.SelectionBackColor = System.Drawing.Color.CadetBlue;
            this.dataGrid1.SelectionForeColor = System.Drawing.Color.WhiteSmoke;
            this.dataGrid1.Size = new System.Drawing.Size(776, 380);
            this.dataGrid1.TabIndex = 19;
            this.dataGrid1.CurrentCellChanged += new System.EventHandler(this.dataGrid1_CurrentCellChanged);
            // 
            // butKetthuc
            // 
            this.butKetthuc.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butKetthuc.Image = ((System.Drawing.Image)(resources.GetObject("butKetthuc.Image")));
            this.butKetthuc.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butKetthuc.Location = new System.Drawing.Point(584, 490);
            this.butKetthuc.Name = "butKetthuc";
            this.butKetthuc.Size = new System.Drawing.Size(68, 25);
            this.butKetthuc.TabIndex = 20;
            this.butKetthuc.Text = "&Kết thúc";
            this.butKetthuc.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butKetthuc.Click += new System.EventHandler(this.butKetthuc_Click);
            // 
            // label2
            // 
            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label2.Location = new System.Drawing.Point(168, 395);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(56, 23);
            this.label2.TabIndex = 23;
            this.label2.Text = "Tên :";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // ten
            // 
            this.ten.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.ten.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ten.Enabled = false;
            this.ten.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ten.Location = new System.Drawing.Point(224, 395);
            this.ten.Name = "ten";
            this.ten.Size = new System.Drawing.Size(320, 21);
            this.ten.TabIndex = 4;
            this.ten.Validated += new System.EventHandler(this.ten_Validated);
            this.ten.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ten_KeyDown);
            // 
            // butMoi
            // 
            this.butMoi.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butMoi.Image = ((System.Drawing.Image)(resources.GetObject("butMoi.Image")));
            this.butMoi.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butMoi.Location = new System.Drawing.Point(205, 490);
            this.butMoi.Name = "butMoi";
            this.butMoi.Size = new System.Drawing.Size(60, 25);
            this.butMoi.TabIndex = 17;
            this.butMoi.Text = "    &Mới";
            this.butMoi.Click += new System.EventHandler(this.butMoi_Click);
            // 
            // butSua
            // 
            this.butSua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butSua.Image = ((System.Drawing.Image)(resources.GetObject("butSua.Image")));
            this.butSua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butSua.Location = new System.Drawing.Point(268, 490);
            this.butSua.Name = "butSua";
            this.butSua.Size = new System.Drawing.Size(60, 25);
            this.butSua.TabIndex = 18;
            this.butSua.Text = "     &Sửa";
            this.butSua.Click += new System.EventHandler(this.butSua_Click);
            // 
            // butLuu
            // 
            this.butLuu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butLuu.Enabled = false;
            this.butLuu.Image = ((System.Drawing.Image)(resources.GetObject("butLuu.Image")));
            this.butLuu.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butLuu.Location = new System.Drawing.Point(331, 490);
            this.butLuu.Name = "butLuu";
            this.butLuu.Size = new System.Drawing.Size(60, 25);
            this.butLuu.TabIndex = 15;
            this.butLuu.Text = "    &Lưu";
            this.butLuu.Click += new System.EventHandler(this.butLuu_Click);
            // 
            // butBoqua
            // 
            this.butBoqua.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butBoqua.Enabled = false;
            this.butBoqua.Image = ((System.Drawing.Image)(resources.GetObject("butBoqua.Image")));
            this.butBoqua.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butBoqua.Location = new System.Drawing.Point(394, 490);
            this.butBoqua.Name = "butBoqua";
            this.butBoqua.Size = new System.Drawing.Size(60, 25);
            this.butBoqua.TabIndex = 16;
            this.butBoqua.Text = "&Bỏ qua";
            this.butBoqua.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.butBoqua.Click += new System.EventHandler(this.butBoqua_Click);
            // 
            // butHuy
            // 
            this.butHuy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.butHuy.Image = ((System.Drawing.Image)(resources.GetObject("butHuy.Image")));
            this.butHuy.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.butHuy.Location = new System.Drawing.Point(457, 490);
            this.butHuy.Name = "butHuy";
            this.butHuy.Size = new System.Drawing.Size(60, 25);
            this.butHuy.TabIndex = 19;
            this.butHuy.Text = "     &Hủy";
            this.butHuy.Click += new System.EventHandler(this.butHuy_Click);
            // 
            // label3
            // 
            this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label3.Location = new System.Drawing.Point(32, 395);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(32, 23);
            this.label3.TabIndex = 24;
            this.label3.Text = "STT :";
            this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // stt
            // 
            this.stt.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.stt.Enabled = false;
            this.stt.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.stt.Location = new System.Drawing.Point(64, 395);
            this.stt.Name = "stt";
            this.stt.Size = new System.Drawing.Size(40, 21);
            this.stt.TabIndex = 2;
            this.stt.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label1
            // 
            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label1.Location = new System.Drawing.Point(544, 395);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(64, 23);
            this.label1.TabIndex = 25;
            this.label1.Text = "Loại :";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // ma
            // 
            this.ma.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.ma.BackColor = System.Drawing.SystemColors.HighlightText;
            this.ma.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper;
            this.ma.Enabled = false;
            this.ma.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.ma.Location = new System.Drawing.Point(128, 395);
            this.ma.MaxLength = 2;
            this.ma.Name = "ma";
            this.ma.Size = new System.Drawing.Size(64, 21);
            this.ma.TabIndex = 3;
            this.ma.Validated += new System.EventHandler(this.ma_Validated);
            this.ma.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // chkHide
            // 
            this.chkHide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.chkHide.Enabled = false;
            this.chkHide.Location = new System.Drawing.Point(376, 467);
            this.chkHide.Name = "chkHide";
            this.chkHide.Size = new System.Drawing.Size(128, 16);
            this.chkHide.TabIndex = 14;
            this.chkHide.Text = "Không sử dụng nữa";
            this.chkHide.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // loai
            // 
            this.loai.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.loai.BackColor = System.Drawing.SystemColors.HighlightText;
            this.loai.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.loai.Enabled = false;
            this.loai.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.loai.Location = new System.Drawing.Point(608, 395);
            this.loai.Name = "loai";
            this.loai.Size = new System.Drawing.Size(176, 21);
            this.loai.TabIndex = 5;
            this.loai.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label5
            // 
            this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label5.Location = new System.Drawing.Point(288, 443);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(88, 23);
            this.label5.TabIndex = 28;
            this.label5.Text = "Số tài khoản :";
            this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label4
            // 
            this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label4.Location = new System.Drawing.Point(88, 395);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(40, 23);
            this.label4.TabIndex = 29;
            this.label4.Text = "Mã :";
            this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // label6
            // 
            this.label6.Location = new System.Drawing.Point(-8, 3);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(72, 23);
            this.label6.TabIndex = 0;
            this.label6.Text = "Chức năng :";
            this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // chucnang
            // 
            this.chucnang.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.chucnang.BackColor = System.Drawing.SystemColors.HighlightText;
            this.chucnang.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.chucnang.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chucnang.Location = new System.Drawing.Point(64, 3);
            this.chucnang.Name = "chucnang";
            this.chucnang.Size = new System.Drawing.Size(720, 21);
            this.chucnang.TabIndex = 1;
            this.chucnang.SelectedIndexChanged += new System.EventHandler(this.chucnang_SelectedIndexChanged);
            this.chucnang.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label7
            // 
            this.label7.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label7.Location = new System.Drawing.Point(-8, 443);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(72, 23);
            this.label7.TabIndex = 32;
            this.label7.Text = "Ngân hàng :";
            this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // idnh
            // 
            this.idnh.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.idnh.BackColor = System.Drawing.SystemColors.HighlightText;
            this.idnh.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.idnh.Enabled = false;
            this.idnh.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.idnh.Location = new System.Drawing.Point(64, 443);
            this.idnh.Name = "idnh";
            this.idnh.Size = new System.Drawing.Size(240, 21);
            this.idnh.TabIndex = 9;
            this.idnh.SelectedIndexChanged += new System.EventHandler(this.idnh_SelectedIndexChanged);
            this.idnh.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // account
            // 
            this.account.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.account.BackColor = System.Drawing.SystemColors.HighlightText;
            this.account.Enabled = false;
            this.account.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.account.Location = new System.Drawing.Point(376, 443);
            this.account.Name = "account";
            this.account.Size = new System.Drawing.Size(168, 21);
            this.account.TabIndex = 10;
            this.account.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label8
            // 
            this.label8.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label8.Location = new System.Drawing.Point(520, 419);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(88, 23);
            this.label8.TabIndex = 35;
            this.label8.Text = "Tên report :";
            this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // report
            // 
            this.report.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.report.BackColor = System.Drawing.SystemColors.HighlightText;
            this.report.Enabled = false;
            this.report.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.report.Location = new System.Drawing.Point(608, 419);
            this.report.Name = "report";
            this.report.Size = new System.Drawing.Size(176, 21);
            this.report.TabIndex = 8;
            this.report.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label9
            // 
            this.label9.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.label9.Location = new System.Drawing.Point(-24, 419);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(88, 23);
            this.label9.TabIndex = 37;
            this.label9.Text = "TK Nợ :";
            this.label9.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // tkno
            // 
            this.tkno.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
                        | System.Windows.Forms.AnchorStyles.Right)));
            this.tkno.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkno.Enabled = false;
            this.tkno.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkno.Location = new System.Drawing.Point(64, 419);
            this.tkno.Name = "tkno";
            this.tkno.Size = new System.Drawing.Size(240, 21);
            this.tkno.TabIndex = 6;
            this.tkno.Validated += new System.EventHandler(this.tkno_Validated);
            this.tkno.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // tkco
            // 
            this.tkco.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.tkco.BackColor = System.Drawing.SystemColors.HighlightText;
            this.tkco.Enabled = false;
            this.tkco.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tkco.Location = new System.Drawing.Point(376, 419);
            this.tkco.Name = "tkco";
            this.tkco.Size = new System.Drawing.Size(168, 21);
            this.tkco.TabIndex = 7;
            this.tkco.Validated += new System.EventHandler(this.tkco_Validated);
            this.tkco.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // label10
            // 
            this.label10.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.label10.Location = new System.Drawing.Point(288, 419);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(88, 23);
            this.label10.TabIndex = 39;
            this.label10.Text = "TK Có :";
            this.label10.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // baocao
            // 
            this.baocao.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.baocao.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
            this.baocao.Enabled = false;
            this.baocao.Location = new System.Drawing.Point(556, 443);
            this.baocao.Name = "baocao";
            this.baocao.Size = new System.Drawing.Size(65, 24);
            this.baocao.TabIndex = 11;
            this.baocao.Text = "Báo cáo";
            this.baocao.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // sophieu
            // 
            this.sophieu.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
            this.sophieu.Enabled = false;
            this.sophieu.Location = new System.Drawing.Point(648, 443);
            this.sophieu.Name = "sophieu";
            this.sophieu.Size = new System.Drawing.Size(136, 24);
            this.sophieu.TabIndex = 12;
            this.sophieu.Text = "Số phiếu tăng tự động";
            this.sophieu.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // dutoanns
            // 
            this.dutoanns.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.dutoanns.Enabled = false;
            this.dutoanns.Location = new System.Drawing.Point(64, 467);
            this.dutoanns.Name = "dutoanns";
            this.dutoanns.Size = new System.Drawing.Size(128, 16);
            this.dutoanns.TabIndex = 13;
            this.dutoanns.Text = "Dự toán ngân sách";
            this.dutoanns.KeyDown += new System.Windows.Forms.KeyEventHandler(this.stt_KeyDown);
            // 
            // btn_in
            // 
            this.btn_in.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.btn_in.Image = ((System.Drawing.Image)(resources.GetObject("btn_in.Image")));
            this.btn_in.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
            this.btn_in.Location = new System.Drawing.Point(520, 490);
            this.btn_in.Name = "btn_in";
            this.btn_in.Size = new System.Drawing.Size(60, 25);
            this.btn_in.TabIndex = 42;
            this.btn_in.Text = "      &In";
            this.btn_in.Click += new System.EventHandler(this.btn_in_Click);
            // 
            // frmBcnghang
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(792, 573);
            this.Controls.Add(this.btn_in);
            this.Controls.Add(this.dutoanns);
            this.Controls.Add(this.sophieu);
            this.Controls.Add(this.chkHide);
            this.Controls.Add(this.baocao);
            this.Controls.Add(this.tkno);
            this.Controls.Add(this.tkco);
            this.Controls.Add(this.label10);
            this.Controls.Add(this.label9);
            this.Controls.Add(this.account);
            this.Controls.Add(this.report);
            this.Controls.Add(this.label8);
            this.Controls.Add(this.idnh);
            this.Controls.Add(this.label7);
            this.Controls.Add(this.stt);
            this.Controls.Add(this.chucnang);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.loai);
            this.Controls.Add(this.label5);
            this.Controls.Add(this.ten);
            this.Controls.Add(this.ma);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.butHuy);
            this.Controls.Add(this.butBoqua);
            this.Controls.Add(this.butLuu);
            this.Controls.Add(this.butSua);
            this.Controls.Add(this.butMoi);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.butKetthuc);
            this.Controls.Add(this.dataGrid1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Name = "frmBcnghang";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Danh mục loại chứng từ";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.frmBcnghang_Load);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.frmBcnghang_KeyDown);
            ((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.stt)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		private void frmBcnghang_Load(object sender, System.EventArgs e)
		{
			user=a.user;
			chucnang.DisplayMember="TEN";
			chucnang.ValueMember="ID";
			chucnang.DataSource=a.get_data("select * from a_dmchucnang where sudung=1 order by stt,id").Tables[0];

			dtnh=a.get_data("select a.*,b.stk as tk from a_dmnh a,a_dmtk b where a.stk=b.id(+) and a.sudung=1 order by a.stt").Tables[0];
			idnh.DisplayMember="TENNH";
			idnh.ValueMember="ID";
			idnh.DataSource=dtnh;

			loai.DisplayMember="TEN";
			loai.ValueMember="ID";
			loai.DataSource=a.get_data("select * from a_dmloaiphieu where sudung=1 order by stt").Tables[0];

			load_grid();
			AddGridTableStyle();
			ref_text();
		}

		private void load_grid()
		{
			string sql="select a.*,b.account,b.tennh,c.ten as tenloai from a_bcnghang a,a_dmnh b,a_dmloaiphieu c ";
			sql+=" where a.idnh=b.id(+) and a.loai=c.id ";
			sql+=" and a.chucnang="+long.Parse(chucnang.SelectedValue.ToString());
			sql+=" order by a.stt";
			dt=a.get_data(sql).Tables[0];
			dataGrid1.DataSource=dt;
		}

		private void AddGridTableStyle()
		{
			DataGridTableStyle ts =new DataGridTableStyle();
			ts.MappingName = dt.TableName;
			ts.AlternatingBackColor = Color.Beige;
			ts.BackColor = Color.GhostWhite;
			ts.ForeColor = Color.MidnightBlue;
			ts.GridLineColor = Color.RoyalBlue;
			ts.HeaderBackColor = Color.MidnightBlue;
			ts.HeaderForeColor = Color.Lavender;
			ts.SelectionBackColor = Color.Teal;
			ts.SelectionForeColor = Color.PaleGreen;
			ts.ReadOnly=false;
			ts.RowHeaderWidth=10;
						
			DataGridTextBoxColumn TextCol=new DataGridTextBoxColumn();			
			TextCol.MappingName = "id";
			TextCol.HeaderText = "";
			TextCol.Width = 0;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "stt";
			TextCol.HeaderText = "STT";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "mact";
			TextCol.HeaderText = "Mã số";
			TextCol.Width = 30;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "ten";
			TextCol.HeaderText = "Tên";
			TextCol.Width = 250;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenloai";
			TextCol.HeaderText = "Loại";
			TextCol.Width = 150;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tennh";
			TextCol.HeaderText = "Ngân hàng";
			TextCol.Width = 200;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "account";
			TextCol.HeaderText = "Số tài khoản";
			TextCol.Width = 120;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkno";
			TextCol.HeaderText = "TK Nợ";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tkco";
			TextCol.HeaderText = "TK Có";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);

			TextCol=new DataGridTextBoxColumn();
			TextCol.MappingName = "tenreport";
			TextCol.HeaderText = "Report";
			TextCol.Width = 100;
			ts.GridColumnStyles.Add(TextCol);
			dataGrid1.TableStyles.Add(ts);
		}

		private void butKetthuc_Click(object sender, System.EventArgs e)
		{
			a.close();System.GC.Collect();this.Close();
		}

		private void ten_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");
		}

		private void ena_object(bool ena)
		{
			dataGrid1.Enabled=!ena;
			report.Enabled=stt.Enabled=ena;
			dutoanns.Enabled=sophieu.Enabled=baocao.Enabled=tkno.Enabled=tkco.Enabled=ten.Enabled=ena;
			if (int.Parse(chucnang.SelectedValue.ToString())==2) idnh.Enabled=ena;
			loai.Enabled=chkHide.Enabled=ma.Enabled=ena;
			chucnang.Enabled=butMoi.Enabled=!ena;
			butSua.Enabled=!ena;
			butLuu.Enabled=ena;
			butBoqua.Enabled=ena;
			butHuy.Enabled=!ena;
			butKetthuc.Enabled=!ena;
		}

		private void butMoi_Click(object sender, System.EventArgs e)
		{
			try
			{
				stt.Value=decimal.Parse(a.get_data("select max(stt) from "+user+".a_bcnghang where chucnang="+long.Parse(chucnang.SelectedValue.ToString())).Tables[0].Rows[0][0].ToString())+1;
			}
			catch{stt.Value=1;}
			l_id=0;
			report.Text=tkno.Text=tkco.Text=ma.Text=ten.Text="";
			baocao.Checked=false;
			dutoanns.Checked=chkHide.Checked=false;
			sophieu.Checked=true;
			ena_object(true);
			stt.Focus();
		}

		private void butSua_Click(object sender, System.EventArgs e)
		{
			if (dt.Rows.Count==0) return;
			l_id=int.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString());
			ena_object(true);
			stt.Focus();
		}

		private bool kiemtra()
		{
			if (ma.Text=="")
			{
				MessageBox.Show("Yêu cầu mã số !",a.Msg);
				ma.Focus();
				return false;
			}
			if (ten.Text=="")
			{
				MessageBox.Show("Yêu cầu nhập tên !",a.Msg);
				ten.Focus();
				return false;
			}
			return true;
		}

		private void butLuu_Click(object sender, System.EventArgs e)
		{
			if (!kiemtra()) return;
			l_id=(l_id==0)?a.getIdbcnghang():l_id;
			if (!a.upd_bcnghang(l_id,stt.Value,ma.Text,ten.Text,(baocao.Checked)?1:0,report.Text,int.Parse(chucnang.SelectedValue.ToString()),tkno.Text,tkco.Text,(chkHide.Checked)?0:1,(idnh.SelectedIndex!=-1)?int.Parse(idnh.SelectedValue.ToString()):0,int.Parse(loai.SelectedValue.ToString()),ma.Text,(sophieu.Checked)?1:0,(dutoanns.Checked)?1:0,i_userid))
			{
				MessageBox.Show("Không cập nhật thông tin "+this.Text.Trim()+" !",a.Msg);
				return;
			}
			load_grid();
			ref_text();
			ena_object(false);
		}

		private void butBoqua_Click(object sender, System.EventArgs e)
		{
			ref_text();
			ena_object(false);
		}

		private void butHuy_Click(object sender, System.EventArgs e)
		{
			try
			{
                //if (a.get_data("select * from "+user+".a_ct"+s_mmyy.Substring(2)+" where lctug="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString())).Tables[0].Rows.Count!=0)
                //{
                //    MessageBox.Show("Nội dung đang sử dụng không cho phép hủy !",a.Msg);
                //    return;
                //}
			}
			catch{}
			if (MessageBox.Show("Đồng ý hủy thông tin này !",a.Msg,MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				a.execute_data("delete from "+user+".a_dmtscd where id="+long.Parse(dataGrid1[dataGrid1.CurrentCell.RowNumber,0].ToString()));
				load_grid();
			}
		}

		private void ref_text()
		{
			try
			{
				int i=dataGrid1.CurrentCell.RowNumber;
				l_id=long.Parse(dataGrid1[i,0].ToString());
				DataRow r=a.getrowbyid(dt,"id="+l_id);
				if (r!=null)
				{
					stt.Value=decimal.Parse(r["stt"].ToString());
					ma.Text=r["mact"].ToString();
					ten.Text=r["ten"].ToString();
					idnh.SelectedValue=r["idnh"].ToString();
					account.Text=r["account"].ToString();
					tkno.Text=r["tkno"].ToString();
					tkco.Text=r["tkco"].ToString();
					report.Text=r["tenreport"].ToString();
					loai.SelectedValue=r["loai"].ToString();
					baocao.Checked=r["baocao"].ToString()=="1";
					chkHide.Checked=r["sudung"].ToString().Trim()=="0";
					sophieu.Checked=r["sophieu"].ToString().Trim()=="1";
					dutoanns.Checked=r["dutoanns"].ToString().Trim()=="1";
				}
			}
			catch{}
		}

		private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
		{
			ref_text();
		}

		private void frmBcnghang_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.F10) butKetthuc_Click(sender,e);
		}

		private void stt_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if (e.KeyCode==Keys.Enter) SendKeys.Send("{Tab}");		
		}

		private void ten_Validated(object sender, System.EventArgs e)
		{
			if (l_id==0 && ten.Text!="")
			{
				DataRow r1=a.getrowbyid(dt,"ten='"+ten.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Tên đã nhập !",a.Msg);
					ten.Focus();
				}
			}
		}

		private void ma_Validated(object sender, System.EventArgs e)
		{
			if (l_id==0 && ma.Text!="")
			{
				DataRow r1=a.getrowbyid(dt,"mact='"+ma.Text+"'");
				if (r1!=null)
				{
					MessageBox.Show("Mã số đã nhập !",a.Msg);
					ma.Focus();
				}
			}
		}

		private void chucnang_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==chucnang) load_grid();
		}

		private void idnh_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (this.ActiveControl==idnh && idnh.SelectedIndex!=-1)
				account.Text=dtnh.Rows[idnh.SelectedIndex]["account"].ToString();
		}

		private void tkno_Validated(object sender, System.EventArgs e)
		{
			if (tkno.Text!="")
			{
				DataRow r=a.getrowbyid(dtnh,"tk='"+tkno.Text+"'");
				if (r!=null)
				{
					account.Text=r["account"].ToString();
					idnh.SelectedValue=r["id"].ToString();
				}
			}
		}

		private void tkco_Validated(object sender, System.EventArgs e)
		{
			if (tkco.Text!="")
			{
				DataRow r=a.getrowbyid(dtnh,"tk='"+tkco.Text+"'");
				if (r!=null)
				{
					account.Text=r["account"].ToString();
					idnh.SelectedValue=r["id"].ToString();
				}
			}
		}

		private void btn_in_Click(object sender, System.EventArgs e)
		{
			DataSet _DataSet =new DataSet();
			_DataSet=a._rdanhmucchungtu(long.Parse(chucnang.SelectedValue.ToString()));
			frmReport _frmReport =new frmReport(a,_DataSet,"11","KT_rdanhmucloaichungtu.rpt");
			_frmReport.ShowDialog();
		}
	}
}
